home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / xvisrc.zip / PARAM.C < prev    next >
C/C++ Source or Header  |  1992-07-28  |  23KB  |  892 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)param.c    2.1 (Chris & John Downey) 7/29/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     param.c
  14. * module function:
  15.     Code to handle user-settable parameters. This is all pretty much
  16.     table-driven. To add a new parameter, put it in the params array,
  17.     and add a macro for it in param.h.
  18.  
  19.     The idea of the parameter table is that access to any particular
  20.     parameter has to be fast, so it is done with a table lookup. This
  21.     unfortunately means that the index of each parameter is recorded
  22.     as a macro in param.h, so that file must be changed at the same
  23.     time as the table below, and in the same way.
  24.  
  25.     When a parameter is changed, a function is called to do the actual
  26.     work; this function is part of the parameter structure.  For many
  27.     parameters, it's just a simple function that prints "not implemented";
  28.     for most others, there are "standard" functions to set bool, numeric
  29.     and string parameters, with a certain amount of checking.
  30.  
  31.     No bounds checking is done here; we should really include limits
  32.     to numeric parameters in the table. Maybe this will come later.
  33.  
  34.     The data structures will be changed again shortly to enable
  35.     buffer- and window-local parameters to be implemented.
  36.  
  37.     One problem with numeric parameters is that they are of type "int";
  38.     this obviously places some restrictions on the sort of things they
  39.     may be used for, and it may be necessary at some point to change
  40.     this type to something like "unsigned long".
  41.  
  42. * history:
  43.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  44.     Originally by Tim Thompson (twitch!tjt)
  45.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  46.     Heavily modified by Chris & John Downey
  47.  
  48. ***/
  49.  
  50. #include "xvi.h"
  51.  
  52. #define nofunc    PFUNCADDR(NULL)
  53.  
  54. /*
  55.  * Default settings for string parameters.
  56.  * These are set by the exported function init_params(),
  57.  * which must be called before any parameters are accessed.
  58.  */
  59. #define    DEF_TAGS    "tags,/usr/lib/tags"
  60. #define    DEF_PARA    "^($|\\.([ILPQ]P|LI|[plib]p))"
  61. #define    DEF_SECTIONS    "^({|\\.([NS]H|HU|nh|sh))"
  62. #define    DEF_SENTENCES    "\\<[A-Z]"
  63.  
  64. /*
  65.  * Default setting for roscolour parameter is the same
  66.  * as the statuscolour if not specified otherwise.
  67.  */
  68. #ifndef    DEF_ROSCOLOUR
  69. #define    DEF_ROSCOLOUR    DEF_STCOLOUR
  70. #endif
  71.  
  72. /*
  73.  * Default settings for showing control- and meta-characters are
  74.  * as for "normal" vi, i.e. "old" xvi without SHOW_META_CHARS set.
  75.  */
  76. #ifndef    DEF_CCHARS
  77. #   define    DEF_CCHARS    FALSE
  78. #endif
  79. #ifndef    DEF_MCHARS
  80. #   define    DEF_MCHARS    FALSE
  81. #endif
  82.  
  83. /*
  84.  * Internal functions.
  85.  */
  86. static    int    strtoi P((char **));
  87. static    bool_t    _do_set P((Xviwin *, char *, bool_t));
  88. static    char    *parmstring P((Param *, int));
  89. static    void    enum_usage P((Xviwin*, Param *));
  90. static    bool_t    not_imp P((Xviwin *, Paramval, bool_t));
  91. static    bool_t    set_magic P((Xviwin *, Paramval, bool_t));
  92. static    bool_t    set_rt P((Xviwin *, Paramval, bool_t));
  93. static    char    *par_show P((void));
  94.  
  95. /*
  96.  * These are the available parameters. The following are non-standard:
  97.  *
  98.  *    autosplit format helpfile jumpscroll preserve
  99.  *    preservetime regextype vbell edit
  100.  *    colour statuscolour roscolour systemcolour
  101.  */
  102. Param    params[] = {
  103. /*  fullname        shortname       flags       value           function ... */
  104. {   "ada",          "ada",          P_BOOL,     0,              not_imp,   },
  105. {   "adapath",      "adapath",      P_STRING,   0,              not_imp,   },
  106. {   "autoindent",   "ai",           P_BOOL,     0,              nofunc,    },
  107. {   "autoprint",    "ap",           P_BOOL,     0,              not_imp,   },
  108. {   "autosplit",    "as",           P_NUM,      2,              nofunc,    },
  109. {   "autowrite",    "aw",           P_BOOL,     0,              not_imp,   },
  110. {   "beautify",     "bf",           P_BOOL,     0,              not_imp,   },
  111. {   "cchars",       "cchars",       P_BOOL,     DEF_CCHARS,     nofunc,    },
  112. {   "colour",       "co",           P_NUM,      DEF_COLOUR,     nofunc,    },
  113. {   "directory",    "dir",          P_STRING,   0,              not_imp,   },
  114. {   "edcompatible", "edcompatible", P_BOOL,     0,              not_imp,   },
  115. {   "edit",         "edit",         P_BOOL,     TRUE,           set_edit,  },
  116. {   "errorbells",   "eb",           P_BOOL,     0,              nofunc,    },
  117. {   "format",       "fmt",          P_ENUM,     0,              set_format,},
  118. {   "hardtabs",     "ht",           P_NUM,      0,              not_imp,   },
  119. {   "helpfile",     "hf",           P_STRING,   0,              nofunc,    },
  120. {   "ignorecase",   "ic",           P_BOOL,     0,              nofunc,    },
  121. {   "jumpscroll",   "js",           P_ENUM,     0,              nofunc,    },
  122. {   "lisp",         "lisp",         P_BOOL,     0,              not_imp,   },
  123. {   "list",         "ls",           P_BOOL,     0,              nofunc,    },
  124. {   "magic",        "magic",        P_BOOL,     TRUE,           set_magic, },
  125. {   "mchars",       "mchars",       P_BOOL,     DEF_MCHARS,     nofunc,    },
  126. {   "mesg",         "mesg",         P_BOOL,     0,              not_imp,   },
  127. {   "minrows",      "min",          P_NUM,      2,              nofunc,    },
  128. {   "modeline",     "modeline",     P_BOOL,     0,              not_imp,   },
  129. {   "number",       "nu",           P_BOOL,     0,              nofunc,    },
  130. {   "open",         "open",         P_BOOL,     0,              not_imp,   },
  131. {   "optimize",     "opt",          P_BOOL,     0,              not_imp,   },
  132. {   "paragraphs",   "para",         P_STRING,   0,              nofunc,    },
  133. {   "preserve",     "psv",          P_ENUM,     0,              nofunc,    },
  134. {   "preservetime", "psvt",         P_NUM,      5,              nofunc,    },
  135. {   "prompt",       "prompt",       P_BOOL,     0,              not_imp,   },
  136. {   "readonly",     "ro",           P_BOOL,     0,              nofunc,       },
  137. {   "redraw",       "redraw",       P_BOOL,     0,              not_imp,   },
  138. {   "regextype",    "rt",           P_ENUM,     0,              set_rt,    },
  139. {   "remap",        "remap",        P_BOOL,     0,              nofunc,    },
  140. {   "report",       "report",       P_NUM,      5,              nofunc,    },
  141. {   "roscolour",    "rst",          P_NUM,      DEF_ROSCOLOUR,  nofunc,    },
  142. {   "scroll",       "scroll",       P_NUM,      0,              not_imp,   },
  143. {   "sections",     "sections",     P_STRING,   0,              nofunc,    },
  144. {   "sentences",    "sentences",    P_STRING,   0,              nofunc,    },
  145. {   "shell",        "sh",           P_STRING,   0,              nofunc,    },
  146. {   "shiftwidth",   "sw",           P_NUM,      8,              nofunc,    },
  147. {   "showmatch",    "sm",           P_BOOL,     0,              nofunc,    },
  148. {   "slowopen",     "slowopen",     P_BOOL,     0,              not_imp,   },
  149. {   "sourceany",    "sourceany",    P_BOOL,     0,              not_imp,   },
  150. {   "statuscolour", "st",           P_NUM,      DEF_STCOLOUR,   nofunc,    },
  151. {   "systemcolour", "sy",           P_NUM,      DEF_SYSCOLOUR,  nofunc,    },
  152. {   "tabs",         "tabs",         P_BOOL,     TRUE,           nofunc,    },
  153. {   "tabstop",      "ts",           P_NUM,      8,              nofunc,    },
  154. {   "taglength",    "tlh",          P_NUM,      0,              nofunc,    },
  155. {   "tags",         "tags",         P_LIST,     0,              nofunc,    },
  156. {   "term",         "term",         P_STRING,   0,              not_imp,   },
  157. {   "terse",        "terse",        P_BOOL,     0,              not_imp,   },
  158. {   "timeout",      "timeout",      P_NUM,      DEF_TIMEOUT,    nofunc,    },
  159. {   "ttytype",      "ttytype",      P_STRING,   0,              not_imp,   },
  160. {   "vbell",        "vb",           P_BOOL,     0,              nofunc,    },
  161. {   "warn",         "warn",         P_BOOL,     0,              not_imp,   },
  162. {   "window",       "window",       P_NUM,      0,              not_imp,   },
  163. {   "wrapmargin",   "wm",           P_NUM,      0,              nofunc,    },
  164. {   "wrapscan",     "ws",           P_BOOL,     TRUE,           nofunc,    },
  165. {   "wri